#include <stdlib.h>
#include "stm32f10x.h"
#include "led.h"  
#include "key.h"  
#include "usart.h" 

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "los_base.h"
#include "los_config.h"
#include "los_typedef.h"
#include "los_hwi.h"
#include "los_task.ph"
#include "los_sem.h"
#include "los_event.h"
#include "los_memory.h"
#include "los_queue.ph"

uint32_t  g_TestTskHandle;

VOID TASK1(void)
{
	UINT32 uwRet = LOS_OK;
	UINT32 count=0;
	while(1)
	{
		count++;
		printf("This is task 1 Running --  %d\r\n",count);

		uwRet = LOS_TaskDelay(1000);
		if(uwRet !=LOS_OK)
			return;
	}
}

UINT32 Creat_TASK1(void)
{
	UINT32 uwRet = LOS_OK;
	TSK_INIT_PARAM_S task_init_param;
	task_init_param.usTaskPrio = 0;
	task_init_param.pcName = "TASK1";
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)TASK1;
	task_init_param.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
	task_init_param.uwResved = LOS_TASK_STATUS_DETACHED;
	uwRet = LOS_TaskCreate(&g_TestTskHandle,&task_init_param);
	if(uwRet !=LOS_OK)
	{
		return uwRet;
	}
	return uwRet;
}

VOID TASK2(void)
{
	UINT32 uwRet = LOS_OK;
	UINT32 count=0;
	while(1)
	{
		count++;
		printf("This is task 2 Running --  %d\r\n",count);
		uwRet = LOS_TaskDelay(2000);
		if(uwRet !=LOS_OK)
			return;
	}
}

UINT32 Creat_TASK2(void)
{
	UINT32 uwRet = LOS_OK;
	TSK_INIT_PARAM_S task_init_param;
	task_init_param.usTaskPrio = 0;
	task_init_param.pcName = "TASK2";
	task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)TASK2;
	task_init_param.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
	task_init_param.uwResved = LOS_TASK_STATUS_DETACHED;
	uwRet = LOS_TaskCreate(&g_TestTskHandle,&task_init_param);
	if(uwRet !=LOS_OK)
	{
		return uwRet;
	}
	return uwRet;
}

UINT32 osAppInit(void)
{
	UINT32 uwRet = 0;
	
	Delay_Init();
        Usart_Config();

printf("\n********Hello Huawei LiteOS********\r\n\r\n"
	"\nLiteOS Kernel Version : %s\r\n\r\n"
		"build data : %s %s\r\n\r\n"
	"**********************************\r\n",
	"Tag.V1.1.0", __DATE__, __TIME__);
	
	uwRet = Creat_TASK1();
	if(uwRet !=LOS_OK)
	{
		return uwRet;
	}
	
	uwRet = Creat_TASK2();
	if(uwRet !=LOS_OK)
	{
		return uwRet;
	}
	return LOS_OK;
}

